﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CLVisionCameraControl
{
    public class HIKAreaScanCameraParameters
    {
        public List<ICLVisionCameraParameterStruct> GetFields()
        {
            return this.GetType()
                .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                .Where(field => field.FieldType == typeof(ICLVisionCameraParameterStruct))
                .Select(field => (ICLVisionCameraParameterStruct)field.GetValue(this))
                .ToList();
        }
        public List<string> GetFieldNames()
        {
            return this.GetType()
                .GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
                .Where(field => field.FieldType == typeof(ICLVisionCameraParameterStruct))
                .Select(f => f.Name)
                .ToList();
        }


        public ICLVisionCameraParameterStruct GetFieldByName(string name)
        {
            var field = this.GetType()
                .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
                .FirstOrDefault(f => f.Name == name && f.FieldType == typeof(ICLVisionCameraParameterStruct));
            if (field != null)
            {
                return (ICLVisionCameraParameterStruct)field.GetValue(this);
            }
            return null;
        }

        ICLVisionCameraParameterStruct AcquisitionMode = new HIKParameterStruct()
        {
            ParameterName = "AcquisitionMode",
            ParameterDescription = "Sets the acquisition mode of the device",
            ParameterType = EnumCameraParameterType.Enum,
            ParameterEnumsList = new List<string> { "Continuous", "SingleFrame" },
            ParameterMaximum = null,
            ParameterMinimum = null,
            ParameterCurrentValue = null
        };


        ICLVisionCameraParameterStruct TriggerMode = new HIKParameterStruct()
        {
            ParameterName = "TriggerMode",
            ParameterDescription = "Controls whether or not the selected trigger is active",
            ParameterType = EnumCameraParameterType.Enum,
            ParameterEnumsList = new List<string> { "Off", "On" },
            ParameterMaximum = null,
            ParameterMinimum = null,
            ParameterCurrentValue = null
        };

        ICLVisionCameraParameterStruct TriggerSource = new HIKParameterStruct()
        {
            ParameterName = "TriggerSource",
            ParameterDescription = "Specifies the internal signal or physical input line to use as the trigger source. The selected trigger must have its TriggerMode set to On",
            ParameterType = EnumCameraParameterType.Enum,
            ParameterEnumsList = new List<string> { "Software", "Line 0", "Line 2", "Counter 0", "Action 1", "Anyway" },
            ParameterMaximum = null,
            ParameterMinimum = null,
            ParameterCurrentValue = null
        };

        ICLVisionCameraParameterStruct ExposureMode = new HIKParameterStruct()
        {
            ParameterName = "ExposureMode",
            ParameterDescription = "Sets the operation mode of the Exposure (or shutter)",
            ParameterType = EnumCameraParameterType.Enum,
            ParameterEnumsList = new List<string> { "Timed" },
            ParameterMaximum = null,
            ParameterMinimum = null,
            ParameterCurrentValue = null
        };

        ICLVisionCameraParameterStruct ExposureTime = new HIKParameterStruct()
        {
            ParameterName = "ExposureTime",
            ParameterDescription = "Exposure time in us when Exposure Mode is Timed",
            ParameterType = EnumCameraParameterType.Float,
            ParameterEnumsList = null,
            ParameterMaximum = 9999248.000000,
            ParameterMinimum = 12.000000,
            ParameterCurrentValue = null
        };


        ICLVisionCameraParameterStruct ExposureAuto = new HIKParameterStruct()
        {
            ParameterName = "ExposureAuto",
            ParameterDescription = "Sets the automatic exposure mode when Exposure Mode is Timed",
            ParameterType = EnumCameraParameterType.Enum,
            ParameterEnumsList = new List<string> { "Off", "Once", "Continuous" },
            ParameterMaximum = null,
            ParameterMinimum = null,
            ParameterCurrentValue = null
        };



        ICLVisionCameraParameterStruct Width = new HIKParameterStruct()
        {
            ParameterName = "Width",
            ParameterDescription = "Width of the image provided by the device (in pixels).",
            ParameterType = EnumCameraParameterType.Integer,
            ParameterEnumsList = null,
            ParameterMaximum = 5120,
            ParameterMinimum = 32,
            ParameterCurrentValue = null
        };

        ICLVisionCameraParameterStruct Height = new HIKParameterStruct()
        {
            ParameterName = "Height",
            ParameterDescription = "Height of the image provided by the device (in pixels).",
            ParameterType = EnumCameraParameterType.Integer,
            ParameterEnumsList = null,
            ParameterMaximum = 5120,
            ParameterMinimum = 8,
            ParameterCurrentValue = null
        };

        ICLVisionCameraParameterStruct OffsetX = new HIKParameterStruct()
        {
            ParameterName = "OffsetX",
            ParameterDescription = "Horizontal offset from the origin to the AOI (in pixels).",
            ParameterType = EnumCameraParameterType.Integer,
            ParameterEnumsList = null,
            ParameterMaximum = 0,
            ParameterMinimum = 0,
            ParameterCurrentValue = null
        };

        ICLVisionCameraParameterStruct OffsetY = new HIKParameterStruct()
        {
            ParameterName = "OffsetY",
            ParameterDescription = "Vertical offset from the origin to the AOI (in pixels).",
            ParameterType = EnumCameraParameterType.Integer,
            ParameterEnumsList = null,
            ParameterMaximum = 0,
            ParameterMinimum = 0,
            ParameterCurrentValue = null
        };

        ICLVisionCameraParameterStruct PixelFormat = new HIKParameterStruct()
        {
            ParameterName = "PixelFormat",
            ParameterDescription = "Vertical offset from the origin to the AOI (in pixels).",
            ParameterType = EnumCameraParameterType.Enum,
            ParameterEnumsList = new List<string> { "Mono 8", "Mono 10", "Mono 12", "RGB 8", "BGR 8", "YUV 422 (YUYV) Packed", "YUV 422 Packed", "Bayer BG 8", "Bayer BG 10", "Bayer BG 10 Packed", "Bayer BG 12", "Bayer BG 12 Packed" },
            ParameterMaximum = 0,
            ParameterMinimum = 0,
            ParameterCurrentValue = null
        };

        ICLVisionCameraParameterStruct Gain = new HIKParameterStruct()
        {
            ParameterName = "Gain",
            ParameterDescription = "Sets the automatic exposure mode when Exposure Mode is Timed",
            ParameterType = EnumCameraParameterType.Float,
            ParameterEnumsList = null,
            ParameterMaximum = 13.965100,
            ParameterMinimum = 0.000000,
            ParameterCurrentValue = null
        };
    }



    public struct HIKParameterStruct : ICLVisionCameraParameterStruct
    {
        public string ParameterName { get; set; }
        public string ParameterDescription { get; set; }
        public EnumCameraParameterType ParameterType { get; set; }
        public List<string> ParameterEnumsList { get; set; }
        public object ParameterMaximum { get; set; }
        public object ParameterMinimum { get; set; }
        public object ParameterCurrentValue { get; set; }
    }
}
